package com.test;//递归实现n的阶乘

import java.util.Random;

public class Factorial{
    //主方法
    public static void main(String[] args){
        for (;;){
            int num = new Random().nextInt(10-1)+1;
            int ret = factorial(num);
            if (num==1) {
                System.out.println(num);
                return;
            }else {
                System.out.println(num + "的阶乘为" + ret);
                System.out.println(num + "的斐波那数为" + a(num));
                System.out.println("第" + num + "天的桃子数为" + peach(num));
                System.out.println(num + "的函数结果为" + f(num));
                System.out.println("---------------------------------");
            }
        }
/*        int[] arr={1,5,33,7,8,27,5,90,2,6,25};
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j+1]<arr[j]) {
                    int t =arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=t;
                }

            }
        }
        System.out.println(Arrays.toString(arr));*/


    }

    //n的阶乘
    public static int factorial(int n){
        if(n == 1){
            return 1;
        }
        else{
            return n*factorial(n-1);
        }
    }

    //已知f(1)=3;f(n)=2*f(n-1)+1,求f(n)的值
    private static int f(int n) {
        if (n==1) {
            return 3;
        }else {
            return 2 * f(n - 1) + 1;
        }
    }

    //猴子吃桃,猴子第十天剩余1个桃子,此前每天吃的桃子都是前一天的一半还多吃一个
    private static int peach(int day) {
        if (day<11) {
            if (day == 10) {
                return 1;
            } else {
                return (peach(day + 1) + 1) * 2;
            }
        }else {
            return 0;
        }
    }

    //求斐波那数,   1,1,2,3,5,8,13,21,...
    private static int a(int n) {
        if (n==1||n==2) {
            return 1;
        }else {
            return a(n-1)+a(n-2);
        }
    }




}